package com.zhilei.controller;

import com.zhilei.base.BaseInfoProperties;
import com.zhilei.grace.result.GraceJSONResult;
import com.zhilei.pojo.Job;
import com.zhilei.pojo.bo.EditJobBO;
import com.zhilei.service.JobService;
import com.zhilei.untils.PagedGridResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 志磊
 */
@Slf4j
@RestController
@RequestMapping("job")
public class JobController extends BaseInfoProperties {

    @Autowired
    private JobService jobService;

    /**
     * 发布职位信息
     *
     * @param editJobBO 职位信息BO类
     */
    @PostMapping("modify")
    public GraceJSONResult modify(@RequestBody @Valid EditJobBO editJobBO) {
        jobService.modify(editJobBO);
        return GraceJSONResult.ok();
    }

    /**
     * 查询发布的职位
     *
     * @param hrId
     * @param companyId
     * @param page
     * @param limit
     * @param status
     * @return
     */
    @PostMapping("hr/jobList")
    public GraceJSONResult jobList(@RequestParam("hrId") String hrId,
                                   @RequestParam("companyId") String companyId,
                                   @RequestParam("page") Integer page,
                                   @RequestParam("limit") Integer limit,
                                   @RequestParam("status") Integer status) {
        PagedGridResult jobList = jobService.getJobList(hrId, companyId, page, limit, status);
        return GraceJSONResult.ok(jobList);
    }

    /**
     * 查询职位详情信息
     *
     * @param hrId
     * @param companyId
     * @param jobId
     * @return
     */
    @PostMapping("hr/jobDetail")
    public GraceJSONResult jobDetail(@RequestParam("hrId") String hrId,
                                     @RequestParam("companyId") String companyId,
                                     @RequestParam("jobId") String jobId) {
        Job job = jobService.jobDetail(hrId, companyId, jobId);
        return GraceJSONResult.ok(job);
    }

    /**
     * 关闭职位信息
     *
     * @param hrId
     * @param companyId
     * @param jobId
     * @return
     */
    @PostMapping("close")
    public GraceJSONResult close(@RequestParam("hrId") String hrId,
                                 @RequestParam("companyId") String companyId,
                                 @RequestParam("jobId") String jobId) {
        jobService.close(hrId, companyId, jobId);
        return GraceJSONResult.ok();
    }

    /**
     * 开放职位信息
     *
     * @param hrId
     * @param companyId
     * @param jobId
     * @return
     */
    @PostMapping("open")
    public GraceJSONResult open(@RequestParam("hrId") String hrId,
                                @RequestParam("companyId") String companyId,
                                @RequestParam("jobId") String jobId) {
        jobService.open(hrId, companyId, jobId);
        return GraceJSONResult.ok();
    }

    /**
     * 历史职位
     *
     * @param page
     * @param limit
     * @return
     */
    @PostMapping("jobList")
    public GraceJSONResult jobList(@RequestParam("page") Integer page,
                                   @RequestParam("limit") Integer limit) {
        PagedGridResult pagedGridResult = jobService.jobList(page, limit);
        return GraceJSONResult.ok(pagedGridResult);
    }

    /**
     * saas端查看招聘详情列表
     *
     * @param jobId
     * @return
     */
    @PostMapping("admin/jobDetail")
    public GraceJSONResult jobDetail(@RequestParam("jobId") String jobId) {
        Job job = jobService.jobDetail(null, null, jobId);
        return GraceJSONResult.ok(job);
    }
}
























